/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worldscale.xp.wspr.event;

import java.util.Enumeration;
import java.util.Vector;

/**
 *
 * @author Kun
 */
public class DefaultEventDispatcher implements IEventDispatcher {

    private final Vector<IEventListener> ht = new Vector<IEventListener>(2);

    public DefaultEventDispatcher() {
    }

    @Override
    public void addListener(IEventListener l) {
        if (!ht.contains(l)) {
            ht.addElement(l);
        }
    }

    @Override
    public void dispatchEvent(WsEvent e) {
        final Enumeration<IEventListener> enu = ht.elements();
        for (; enu.hasMoreElements();) {
            enu.nextElement().onEvent(e, this);
        }
    }

    @Override
    public void removeListener(IEventListener l) {
        ht.remove(l);
    }
}
